/*
Java board game library.
Copyright (C) 2011  Deepesh Garg

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


package d.g.boardgames.soccer ;


import java.awt.Color;
import java.awt.Image ;
import java.io.* ;
import java.util.List;

import javax.imageio.ImageIO ;

import d.g.boardgames.Board;
import d.g.boardgames.Cell;
import d.g.boardgames.DefaultBoardRenderProperties;

import static d.g.boardgames.soccer.SoccerBoard.*;

public class SoccerBoardRenderProperties extends DefaultBoardRenderProperties {

	Image backgroundImage ;
	Image redImage ;
	Image blueImage ;
	Image redBallImage ;
	Image blueBallImage ;

	public SoccerBoardRenderProperties () {
		try {
			backgroundImage = ImageIO.read (new File ("./ground.gif")) ;
			redImage = ImageIO.read (new File ("./red.gif")) ;
			blueImage = ImageIO.read (new File ("./blue.gif")) ;
			redBallImage = ImageIO.read (new File ("./red_ball.gif")) ;
			blueBallImage = ImageIO.read (new File ("./blue_ball.gif")) ;
		} catch (Exception e) {
			e.printStackTrace() ;
		}
		
	}

	public Image getBackgroundImage () {
		return backgroundImage ;
	}

	public Image getCellImage (Board board, int row, int col) {
		SoccerBoard sb = (SoccerBoard) board ;
		Object cellState = sb.getCellState(row, col) ;
		if (cellState instanceof SoccerCellState) {
			SoccerCellState sCellState = (SoccerCellState) cellState ;
			if (sCellState.getPlayer() == Player.RED) {
				if (sCellState.getPossesBall() == true) {
					return redBallImage ;
				} else {
					return redImage ;
				}
			}
			if (sCellState.getPlayer() == Player.BLUE) {
				if (sCellState.getPossesBall() == true) {
					return blueBallImage ;
				} else {
					return blueImage ;
				}
			}
		}
		return null ;
	}
	
	public Color getCellBorderColor (Board board, int row, int col) {
		SoccerBoard sb = (SoccerBoard) board ;
		List<Cell> validMoveList = sb.getValidMoveList() ;
		if (validMoveList != null) {
			if(validMoveList.contains(new Cell(row, col))) {
				return Color.yellow ;
			}
		}
		return null;
	}
}
